package com.lineage.server.command.executor;

import com.lineage.server.datatables.sql.CharacterTable;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1CharName;
import com.lineage.server.world.World;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1ResetTime implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1ResetTime.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1ResetTime();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      L1CharName[] charNameList;
      int length = (charNameList = CharacterTable.get().getCharNameList()).length;
      int i = 0;
      while (i < length) {
        L1CharName charName = charNameList[i];
        L1PcInstance tgpc = World.get().getPlayer(charName.getName());
        if (tgpc != null) {
          tgpc.resetAllMapTime();
          tgpc.save();
          tgpc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fT限时地监的使用时间已重置。"));
        } else {
          L1PcInstance offlinepc = CharacterTable.get().restoreCharacter(charName.getName());
          offlinepc.resetAllMapTime();
          offlinepc.save();
        } 
        i++;
      } 
      if (pc == null) {
        _log.warn("系统命令执行: " + cmdName + "重置所有玩家限时地监时间。");
      } else {
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("重置所有玩家限时地监时间。"));
      } 
    } catch (Exception e) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(261));
    } 
  }
}
